package com.hetao.jmb2c.controller;

import com.hetao.jmb2c.common.Result;
import com.hetao.jmb2c.dto.AdminLoginDTO;
import com.hetao.jmb2c.service.AdminService;
import com.hetao.jmb2c.vo.AdminInfoVO;
import com.hetao.jmb2c.vo.AdminLoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Tag(name = "管理员管理", description = "管理员登录和信息获取接口")
@Slf4j
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;
    @Operation(summary = "管理员登录", description = "使用用户名和密码登录管理系统")
    @PostMapping("login")
    public Result<AdminLoginVO> login(
            @Parameter(description = "登录参数", required = true)
            @RequestBody AdminLoginDTO adminLoginDTO) {
        log.info("adminLoginDTO:{}", adminLoginDTO);
        AdminLoginVO adminLoginVO = adminService.login(adminLoginDTO);
        return Result.success(adminLoginVO);
    }

    @Operation(summary = "获取管理员信息", description = "获取当前登录管理员的基本信息")
    @PostMapping("info")
    public Result<AdminInfoVO> info() {
        AdminInfoVO adminInfoVO = this.adminService.info();
        return Result.success(adminInfoVO);
    }
}
